package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.common.utils.AliOssUtil;
import com.atguigu.lease.web.admin.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@Service
@Slf4j
public class FileServiceImpl implements FileService {

    @Autowired
    AliOssUtil aliOssUtil;
    @Override
    public String upload(MultipartFile file) throws IOException {
        log.info("文件上传：{}", file);
            String originalFilename = file.getOriginalFilename();
            String s = originalFilename.substring(originalFilename.lastIndexOf("."));
            String name = UUID.randomUUID().toString() + s;
            String upload = aliOssUtil.upload(file.getBytes(), name);
            return upload;
    }
}
